package code.rocky.consumer;

public class JoinTest2 {

    public static void main(String[] args) {
        Object obj = new Object();
        Thread t1 = new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "  start ...");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "  end ...");
        }, "t1");
        t1.start();
        Thread t2 = new Thread(() -> {
            synchronized (obj) {
                System.out.println(Thread.currentThread().getName() + "  start ...");
                try {
                    obj.wait(2000);
                    System.out.println(Thread.currentThread().getName() + " isalive: " + t1.isAlive());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "  wakeup ...");

            }
        }, "t2");

        t2.start();

        Thread t3 = new Thread(()->{
            synchronized (obj) { // 一定要在同步代码块里面,否则报错 // 1.加锁
                obj.notify(); // 2.唤醒
            } // 3.释放锁
        },"t3");
        t3.start();
    }
}
